package yu.zhou.njupt.importdataui.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

import org.apache.commons.dbutils.DbUtils;

public class DbUtil {

    public static Connection getConnection(Properties config, String dbName) throws Exception{
        Connection conn = null;

        Class.forName(config.getProperty(dbName + ".jdbc.driverClass"));
        
        System.out.println(config.getProperty(dbName + ".jdbc.url"));
        System.out.println(config.getProperty(dbName +".jdbc.username"));
        System.out.println(config.getProperty(dbName + ".jdbc.password"));

        conn = DriverManager.getConnection(
                config.getProperty(dbName + ".jdbc.url"),
                config.getProperty(dbName +".jdbc.username"),
                config.getProperty(dbName + ".jdbc.password"));

        return conn;
    }

    public static void closeConnection(Connection conn){
        DbUtils.closeQuietly(conn);
    }

}
